package main

import (
	"2302a/testyuekao/api/handler"
	"2302a/testyuekao/config"
	"2302a/testyuekao/consts"
	"2302a/testyuekao/inits"
	"2302a/testyuekao/internal/model"
	"2302a/testyuekao/internal/queue"
	"encoding/json"
	"fmt"
	"log"
)

func main() {
	config.InitsConfig()
	inits.InitMysql()
	inits.InitRedis()
	inits.InitRabbitMq()
	msgs := queue.PublishSub(consts.UPDATE_HOUSEP_RICE)
	forever := make(chan bool)

	go func() {
		for d := range msgs {
			log.Printf("Received a message: %s", d.Body)
			var data model.Houses
			_ = json.Unmarshal(d.Body, &data)
			for _, conn := range handler.ClineMap {
				handler.WSRespSuccess(conn, fmt.Sprintf("%s价格调整%d万", data.Title, data.Price/10000))
			}
		}
	}()
	log.Printf(" [*] Waiting for messages. To exit press CTRL+C")
	<-forever
}
